const {
	createApp
} = Vue;
var app = createApp({
	data() {
		return {
			batch: {
				id: 0,
				pdfList: []
			},email:null,window:window,
			statusList: []
		}
	},
	methods: {
		build: function() {
			axios.post('/makeup/batch/produce1007/build?id=' + this.batch.id, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},updateTradeStatus:function(batch){
		    axios.post('/makeup/batch/produce1007/trade/status/update?id=' + this.batch.id, {}).then(function(
            					response) {})
            				.catch(function(error) {
            					console.log("error", error);
            				})
		}, buildPdf: function(batch, pdf) {
			var url = '/makeup/batch/produce1007/pdf/build?1=1';

			if (batch) url = url + "&batchId=" + batch.id;
			if (pdf) url = url + "&pdfId=" + pdf.id;
			axios.post(url, {}).then(function(response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildMarkPdf: function(pdf) {			
			axios.post('/makeup/batch/produce1007/pdf/mark/build?id=' + pdf.id, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildLegendPdf: function(pdf) {
			var url='/makeup/batch/produce1007/pdf/legend/build?batchId='+this.batch.id ;
			if(pdf) url+="&pdfId="+pdf.id;
			axios.post(url, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildCutPdf: function(pdf) {
			var url = '/makeup/batch/produce1007/pdf/cut/build?batchId=' + this.batch.id;
			if (pdf) {
				url = '/makeup/batch/produce1007/pdf/cut/build?batchId=' + this.batch.id + "&id=" + pdf.id;
			}
			axios.post(url, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		pricing: function(pdf) {
			var url = '/makeup/batch/produce1007/pdf/pricing?batchId=' + this.batch.id;
			if (pdf) {
				url = url + "&id=" + pdf.id;
			}
			axios.post(url, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildCoverPdf: function(pdf) {
			axios.post('/makeup/batch/produce1007/pdf/cover/build?id=' + pdf.id, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildScheme: function(pdf) {
			axios.post('/makeup/batch/produce1007/pdf/scheme/build?id=' + pdf.id, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		uploadBaiduPan: function(batch,pdf) {			
			var url='/makeup/pdf/baidu/pan/upload?1=1';
			if (batch) url = url + "&batchId=" + batch.id;
			if (pdf) url = url + "&id=" + pdf.id;
			axios.post(url, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		deleteBaiduPan: function(batch,pdf) {			
			var url='/makeup/pdf/baidu/pan/delete?1=1';
			if (batch) url = url + "&batchId=" + batch.id;
			if (pdf) url = url + "&id=" + pdf.id;
			axios.post(url, {}).then(function(
					response) {})
				.catch(function(error) {
					console.log("error", error);
				})
		},
		buildMiandan: function(batch, pdf) {
			var url = "/makeup/batch/miandan/build?i=1";
			if (batch) url = url + "&batchId=" + batch.id;
			if (pdf) url = url + "&pdfId=" + pdf.id;
			axios.post(url, {}).then(function(response) {
				loadData();
			}).catch(function(error) {
				console.log("error", error);
				//loadData();
			});
		},
		prettyFileLength: function(len) {
			if (!len) return null;
			if (len < 1024 * 1024) return (len / 1024.0).toFixed(2) + "K";
			return (len / (1024 * 1024.0)).toFixed(2) + "M";
		},
		excludeGroup: function(batch, pdf) {
			var url = "/makeup/batch/produce1007/exclude/group?1=1";
			if (batch) url = url + "&batchId=" + batch.id;
			if (pdf) url = url + "&pdfId=" + pdf.id;
			axios.post(url, {}).then(function(response) {
				loadData();
			}).catch(function(error) {
				console.log("error", error);
				//loadData();
			});
		},
		sendCutMail: function(batch, pdf) {
			var url = "/makeup/batch/produce1007/cut/mail/send?batchId="+this.batch.id;
			//if (batch) url = url + "&batchId=" + batch.id;
			//if (pdf) url = url + "&pdfId=" + pdf.id;
			var email = this.email;
			if(email)url = url + "&email=" + email;
			axios.post(url, {}).then(function(response) {
				//loadData();
			}).catch(function(error) {
				console.log("error", error);
				//loadData();
			});
		},
		sendLegendMail: function(batch, pdf) {
			var url = "/makeup/batch/produce1007/legend/mail/send?batchId="+this.batch.id;
			//if (batch) url = url + "&batchId=" + batch.id;
			//if (pdf) url = url + "&pdfId=" + pdf.id;
			var email = this.email;
			if(email)url = url + "&email=" + email;
			axios.post(url, {}).then(function(response) {
				//loadData();
			}).catch(function(error) {
				console.log("error", error);
				//loadData();
			});
		}
	},
	watch: {
		selector: {
			handler: function(nv, ov) {},
			deep: true
		}
	}
}).mount('#app');


function loadData() {
	var selector = {
		id: _QS['id'],
		withPdfIdList: 1,
		withTradeIdList: 1,
		withGroupIdList: 1,
		withPdfList: 1,
		pdfSelector: {
			withScheme: 1
		}
	}
	axios.post('/makeup/batch/get?id=' + _QS['id'], selector).then(function(response) {
		console.log("response", response)
		app.$data.batch = response.data.data || {};
		var batch = app.$data.batch;
		if (!app.$data.statusList.length && response.data.statusList) {
			app.$data.statusList = response.data.statusList;
		}
		for(var i= 0;i<batch?.pdfList?.length;i++){
		    if(!batch?.pdfList[i]?.scheme) continue;
		    batch.pdfList[i].schemeJson = JSON.parse(batch.pdfList[i].scheme);
		}

		//app.$data.request.fromStatus = batch.status;
	}).catch(function(error) {
		console.log("error", error);
	});
}

window.addEventListener("load", loadData);

//httpPost("/makeup/batch/manual/step1?id=582710814801268736",{target:{scene:'pay'}})

export {
	app
}